package com.example.changecode;

import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class Conversion {

    private static final List<Character> CASE = Arrays.asList(' ', '_', '-');

    public static List<String> transFrom(String text) {
        List<String> hashSet = new ArrayList<>();
        List<String> words = new ArrayList<>();
        if (text != null && !text.isEmpty()) {
            char[] chars = text.toCharArray();
            StringBuilder word = new StringBuilder();
            for (int j = 0; j < chars.length; j++) {
                if (CASE.contains(chars[j])) {
                    if (word.length() > 0) {
                        words.add(word.toString());
                        word = new StringBuilder();
                    }
                    continue;
                }
                if(Character.isUpperCase(chars[j])) {
                    if(word.length() > 0) {
                        words.add(word.toString());
                    }
                    word = new StringBuilder();
                    word.append(chars[j]);
                    if(j == chars.length - 1) {
                        words.add(word.toString());
                    }
                    continue;
                }
                word.append(chars[j]);
                if(j == chars.length-1 && word.length() > 0) {
                    words.add(word.toString());
                }
            }
        }
        if(!words.isEmpty()) {
            StringBuilder stringBuilder = new StringBuilder();
            for (int i = 0; i < words.size(); i++) {
                String word = words.get(i);
                if(i == 0) {
                    String uncapitalize = StringUtils.uncapitalize(word);
                    stringBuilder.append(uncapitalize);
                }else if(word.length() == 1) {
                    stringBuilder.append(word.toLowerCase());
                }else {
                    stringBuilder.append(StringUtils.capitalize(word));
                }
            }
            hashSet.add(stringBuilder.toString());
            hashSet.add(words.stream().map(String::toLowerCase).collect(Collectors.joining("_")));
            hashSet.add(words.stream().map(String::toLowerCase).collect(Collectors.joining("-")));
            hashSet.add(words.stream().map(String::toUpperCase).collect(Collectors.joining("_")));
            hashSet.add(words.stream().map(StringUtils::capitalize).collect(Collectors.joining()));
            hashSet.add(words.stream().map(StringUtils::capitalize).collect(Collectors.joining(" ")));
            hashSet.add(words.stream().map(String::toUpperCase).collect(Collectors.joining(" ")));
        }
        return hashSet;
    }
}
